//
//  UploadMessageView.m
//  WideHelp
//
//  Created by ENERGY on 2018/8/15.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "UploadMessageView.h"

@implementation UploadMessageView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.alpha = 0;
        UIButton * bgBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, SCREEN_HEIGHT - BOTTOM_HEIGHT)];
        [bgBtn setBackgroundColor:[UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:0.75]];
        [bgBtn addTarget:self action:@selector(cancelClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:bgBtn];
        
        UIView * whiteBGView = [[UIView alloc] init];
        whiteBGView.backgroundColor = [UIColor whiteColor];
        whiteBGView.layer.cornerRadius = 4;
        whiteBGView.layer.masksToBounds = YES;
        [self addSubview:whiteBGView];
        
        UILabel * titleLab = [[UILabel alloc] init];
        titleLab.text = @"提示";
        titleLab.textColor = [UIColor blackColor];
        titleLab.font = DEF_FontSize_14;
        titleLab.backgroundColor = [UIColor clearColor];
        titleLab.textAlignment = NSTextAlignmentCenter;
        [whiteBGView addSubview:titleLab];
        
        UILabel * contentLab = [[UILabel alloc] init];
        contentLab.text = @"购买互助计划等后期完成后，才可申请互助哦！";
        contentLab.textColor = getColor(@"9b9b9b");
        contentLab.font = DEF_FontSize_12;
        contentLab.textAlignment = NSTextAlignmentCenter;
        [whiteBGView addSubview:contentLab];
        
        UIView * lineView = [[UIView alloc] init];
        lineView.backgroundColor = getColor(@"eeeeee");
        [whiteBGView addSubview:lineView];
        
        UIButton * cancenlBtn = [[UIButton alloc] init];
        [cancenlBtn setTitle:@"知道了" forState:UIControlStateNormal];
        [cancenlBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        cancenlBtn.titleLabel.font = DEF_FontSize_13;
        [cancenlBtn addTarget:self action:@selector(cancelClick) forControlEvents:UIControlEventTouchUpInside];
        [whiteBGView addSubview:cancenlBtn];
        
        //masorny
        __weak typeof (self)weakSelf = self;
        [whiteBGView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.mas_left).mas_offset(29/WIDTH_6_SCALE);
            make.bottom.equalTo(weakSelf.mas_centerY);
            make.height.mas_offset(105/WIDTH_6_SCALE);
            make.right.equalTo(weakSelf.mas_right).mas_offset(-29/WIDTH_6_SCALE);
        }];
        [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.equalTo(whiteBGView);
            make.height.mas_offset(34/WIDTH_6_SCALE);
        }];
        [contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(whiteBGView);
            make.top.equalTo(titleLab.mas_bottom);
            make.height.mas_offset(14/WIDTH_6_SCALE);
        }];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(whiteBGView);
            make.height.mas_offset(1/WIDTH_6_SCALE);
            make.top.equalTo(contentLab.mas_bottom).mas_offset(14/WIDTH_6_SCALE);
        }];
        [cancenlBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(whiteBGView);
//            make.height.mas_offset(20/WIDTH_6_SCALE);
            make.top.equalTo(lineView.mas_bottom);
            make.bottom.equalTo(whiteBGView.mas_bottom);
        }];
    }return self;
}
#pragma mark - action
- (void)cancelClick{
    [UIView animateWithDuration:.15 animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}
- (void)show{
    [[UIApplication sharedApplication].delegate.window addSubview:self];
    [UIView animateWithDuration:.15 animations:^{
        self.alpha = 1;
    }];
}
@end
